home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dflat2.zip / RECT.C < prev    next >
Text File  |  1991-04-19  |  3KB  |  110 lines

  1. /* ------------- rect.c --------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. /*
  6.  * Produce the vector end points produced by the overlap
  7.  * of two other vectors
  8.  */
  9. static void subVector(int *v1, int *v2,
  10.                         int t1, int t2, int o1, int o2)
  11. {
  12.     *v1 = *v2 = -1;
  13.     if (within(o1, t1, t2))    {
  14.         *v1 = o1;
  15.         if (within(o2, t1, t2))
  16.             *v2 = o2;
  17.         else
  18.             *v2 = t2;
  19.     }
  20.     else if (within(o2, t1, t2))    {
  21.         *v2 = o2;
  22.         if (within(o1, t1, t2))
  23.             *v1 = o1;
  24.         else
  25.             *v1 = t1;
  26.     }
  27.     else if (within(t1, o1, o2))    {
  28.         *v1 = t1;
  29.         if (within(t2, o1, o2))
  30.             *v2 = t2;
  31.         else
  32.             *v2 = t2;
  33.     }
  34.     else if (within(t2, o1, o2))    {
  35.         *v2 = t2;
  36.         if (within(t1, o1, o2))
  37.             *v1 = t1;
  38.         else
  39.             *v1 = o1;
  40.     }
  41. }
  42.  
  43. /*
  44.  * Return the rectangle produced by the overlap
  45.  * of two other rectangles
  46.  */
  47. RECT subRectangle(RECT r1, RECT r2)
  48. {
  49.     RECT r = {0,0,0,0};
  50.     subVector((int *) &RectLeft(r), (int *) &RectRight(r),
  51.         RectLeft(r1), RectRight(r1),
  52.         RectLeft(r2), RectRight(r2));
  53.     subVector((int *) &RectTop(r), (int *) &RectBottom(r),
  54.         RectTop(r1), RectBottom(r1),
  55.         RectTop(r2), RectBottom(r2));
  56.     if (RectRight(r) == -1 || RectTop(r) == -1)
  57.         RectRight(r) =
  58.         RectLeft(r) =
  59.         RectTop(r) =
  60.         RectBottom(r) = 0;
  61.     return r;
  62. }
  63.  
  64. /*
  65.  * Assumes that r1 is a proper subset of r2
  66.  * Returns rectangle that is relative position of r1 within r2
  67.  */
  68. RECT RelativeRectangle(RECT r1, RECT r2)
  69. {
  70.     RECT rc;
  71.     RectLeft(rc) = RectLeft(r1) - RectLeft(r2);
  72.     RectTop(rc) = RectTop(r1) - RectTop(r2);
  73.     RectBottom(rc) = RectTop(rc) + RectHeight(r1) - 1;
  74.     RectRight(rc) = RectLeft(rc) + RectWidth(r1) - 1;
  75.     return rc;
  76. }
  77.  
  78. /* ---------- return the client rectangle of a window ------ */
  79. RECT ClientRect(void *wnd)
  80. {
  81.     RECT rc = ((WINDOW)wnd)->rc;
  82.     if (TestAttribute((WINDOW)wnd, HASBORDER))    {
  83.         RectLeft(rc)++;
  84.         RectRight(rc)--;
  85.     }
  86.     if (WindowHeight((WINDOW)wnd) > 1 &&
  87.         (GetClass((WINDOW)wnd) != EDITBOX ||
  88.             TestAttribute((WINDOW)wnd, MULTILINE)))    {
  89.         RectTop(rc)++;
  90.         RectBottom(rc)--;
  91.         if (TestAttribute((WINDOW)wnd, HASMENUBAR))
  92.             RectTop(rc)++;
  93.     }
  94.     return rc;
  95. }
  96.  
  97. /*
  98.  * Initialize a rectangle
  99.  */
  100. RECT SetRect(int lf, int tp, int rt, int bt)
  101. {
  102.     RECT rc;
  103.     rc.lf = lf;
  104.     rc.tp = tp;
  105.     rc.rt = rt;
  106.     rc.bt = bt;
  107.     return rc;
  108. }
  109.  
  110.